import sys
import os
import os.path
import shutil

from jinja2 import Environment, PackageLoader, Template, FileSystemLoader

import mdf.debug as debug
import mdf.config as config
import mdf.utils as utils

loader = FileSystemLoader( config.default_template_dir )
env = Environment( loader = loader )

P_BSD="bsd"
P_LIN="lin"
#not permament place of info storage
class Project:
	def __init__( self, name, descr, url, cvssrc, lastlog, platform, fname ):
		self.name = name
		self.descr = descr
		self.url = url
		self.cvssrc = cvssrc
		self.lastlog = lastlog
		self.platform = platform
		self.fname = fname

pr = []
pr.append( Project("robatik",
"Small robot programming game",
["http://code.google.com/p/robatik/"],
["http://code.google.com/p/robatik/source/browse/"],
"",
["bsd","lin"],
"http://robatik.googlecode.com/files/robatik0.1.3.zip"))

pr.append( Project("reprbin",
"Convert binary from/to different formats",
["http://code.google.com/p/represent-binary-file/"],
["http://code.google.com/p/represent-binary-file/source/browse/"],
"",
["bsd","lin"],
"http://represent-binary-file.googlecode.com/files/reprbin.zip") )

pr.append( Project("pamjson",
"LinuxPAM json file based authenitication",
["https://github.com/FreeArtMan/pamjson"],
["https://github.com/FreeArtMan/pamjson",
"http://code.google.com/p/pamjson/source/browse/"],
"",
["bsd","lin"],
"") )

pr.append( Project("csvlog",
"Supports csv format files for loging. Adding line by line csv formated log file.",
["http://code.google.com/p/csvlog/"],
["http://code.google.com/p/csvlog/source/browse/"],
"",
["bsd","lin"],
"http://csvlog.googlecode.com/files/csvlog1.0.tar.gz") )

pr.append( Project("i2csg",
"alfa stage simple i2c interface usage utility",
["http://code.google.com/p/i2csg/"],
["http://code.google.com/p/i2csg/source/browse/"],
"",
["bsd","lin"],
"") )

pr.append( Project("tiny-map-editor",
"Convert binary from/to different formats",
["http://code.google.com/p/tiny-map-editor/"],
["http://code.google.com/p/tiny-map-editor/source/browse/"],
"",
["bsd","lin"],
"http://tiny-map-editor.googlecode.com/files/mape-0.1.2.zip") )

pr.append( Project("gpsr",
"Serial GPS data reading utility",
["http://main.lv/writeup/serial_gps_data_reading_utility.html"],
["https://git.main.lv/?p=gpsr.git"],
"",
["bsd","lin"],
"http://main.lv/files/writeup/serial_gps_data_reading_utility/gpsr.tar.gz") )

pr.append( Project("kconfig2h",
"Convert kconfig kernel config files to c header",
["http://code.google.com/p/kconfig2h/"],
["https://github.com/FreeArtMan/kconfig2h",
"http://code.google.com/p/kconfig2h/source/browse/"],
"",
["bsd","lin"],
"http://code.google.com/p/kconfig2h/") )


class Projects:
	def __init__( self, filename ):
		self.filename = filename
		debug.dprint( filename )
	
	def render( self ):
		#generate template
		templ = env.get_template("projects.thtml")
		f = open( self.filename, "w" )
		f.write( templ.render( projects=pr ) )
		f.close()
